package cn.autumnorange.app.util.provider.rest;

import cn.autumnorange.app.common.dto.ResultDto;
import cn.autumnorange.app.util.api.TimeService;
import cn.autumnorange.app.util.api.dto.OrderDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wsf
 * @time 2019/6/7 22:09
 */
@RestController
public class TimeRest implements TimeService {
  @Autowired private TimeService timeService;
  //计数 统计当前首次请求+重试服务访问总次数
  int count=0;
  @Value("${server.port}")
  private int port;
  @Override
  public ResponseEntity<ResultDto<String>> timestampToYYMMDD(@PathVariable(value = "timestamp") long timestamp) {
    return timeService.timestampToYYMMDD(timestamp);
  }
  @Override
  public ResponseEntity<ResultDto<String>> getAnnotation(@PathVariable(value = "className") String className, @PathVariable(value = "methodName") String methodName, @PathVariable(value = "annotationName") String annotationName) {
    count=count+1;
    if(className.equals("RPCIdempotentLockTargetCheckTest")){
      count=0;
    }
    System.out.println(port+  "  " +count);
//    Annotation annotation= AnnotationUtil.checkAnnotation(className, methodName,  annotationName, true, true);
    return timeService.getAnnotation(className,methodName,annotationName);
  }

  @Override
  public ResponseEntity<ResultDto<OrderDto>> updOrder(@RequestBody OrderDto orderDto) throws Exception {
    return timeService.updOrder(orderDto);
  }
}
